<%-- 
    Document   : decorator
    Created on : Feb 14, 2012, 12:17:51 AM
    Author     : eugene
--%>

<%@page import="knowledgebase.consts.Consts"%>
<%@page import="org.springframework.security.core.authority.SimpleGrantedAuthority"%>
<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <title>KnowledgeBase: <sitemesh:write property='title'/></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%
            // TODO: change this by AppContentHelper
            String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "" + request.getContextPath();
        %>
        <link rel="stylesheet" type="text/css" href="<%=url%>/css/bootstrap.css"/>
        <link rel="stylesheet" type="text/css" href="<%=url%>/css/bootstrap-responsive.css"/>
        <link rel="stylesheet" type="text/css" href="<%=url%>/css/main.css"/>
        <script type="text/javascript" src="<%=url%>/js/jquery-1.7.1.js"></script>
        <script type="text/javascript" src="<%=url%>/js/bootstrap.js"></script>
        <script type="text/javascript" src="<%=url%>/js/notifier.js"></script>
    <sitemesh:write property='head'/>
    <script>
        $(".close").live("click", function() {
            $(this).parent().fadeOut();
        });
    </script>
</head>
<body>
    <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <a class="brand" href="<%=url%>/">Knowledge Base</a>
            <div class="container" style="width: 100%">
                <ul class="nav">
                    <c:if test="<%=!SecurityContextHolder.getContext().getAuthentication().getAuthorities().contains(new SimpleGrantedAuthority(Consts.ROLE_ANONYMOUS))%>">
                        <li class="dropdown">
                            <a href="#"
                               class="dropdown-toggle"
                               data-toggle="dropdown">
                                Articles
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="<%=url%>/article/create.html">Create article</a>
                                </li>
                                <li>
                                    <a href="<%=url%>/article/user_articles.html">View my articles</a>
                                </li>
                            </ul>
                        </li>
                    </c:if>
                    <c:if test="<%=SecurityContextHolder.getContext().getAuthentication().getAuthorities().contains(new SimpleGrantedAuthority(Consts.ROLE_ADMIN))%>">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                Admin Panel
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="<%=url%>/manage_users_and_roles.html">Manage Users and Roles</a>
                                </li>
                                <li>
                                    <a href="<%=url%>/manage_permissions.html">Manage Permissions</a>
                                </li>
                            </ul>
                        </li>
                    </c:if>
                </ul>
                <ul class="nav pull-right">
                    <li class="divider-vertical"></li>
                    <c:choose>
                        <c:when test="<%=SecurityContextHolder.getContext().getAuthentication().getAuthorities().contains(new SimpleGrantedAuthority(Consts.ROLE_ANONYMOUS))%>">
                            <li><a href="<%=url%>/login.html">Log In</a></li>
                            <li><a href="<%=url%>/registration.html">Registration</a></li>
                        </c:when>
                        <c:otherwise>
                            <li><a href="<%=url%>/j_spring_security_logout"><span id="session_counter"></span>&nbsp;<i class="icon-off icon-white"></i></a></li>
                            <!--starts session counter-->
                            <script src="<%=url%>/js/session_counter.js" type="text/javascript"></script>
                        </c:otherwise>
                    </c:choose>
                </ul>
            </div>
        </div>
    </div>

    <div>
        <sitemesh:write property='body'/>
    </div>
</body>
</html>
